package com.the4man.cnbdw.action;

import com.opensymphony.xwork2.ModelDriven;
import com.the4man.cnbdw.service.*;
import com.the4man.cnbdw.utils.*;
import com.the4man.framework.action.BaseAction;
import com.the4man.framework.model.*;
import com.the4man.framework.model.Page;
import com.the4man.framework.model.gen.DeviceExampleBase;
import com.the4man.framework.model.gen.EmployeeDeviceExampleBase;
import com.the4man.framework.util.DateUtil;
import com.the4man.framework.util.LOG;
import com.the4man.framework.util.PageJson;
import com.the4man.framework.utils.GenUtil;
import com.the4man.framework.utils.RequestUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.*;

@Action(
        value = "employeeAction",
        results = {@Result(
                name = "addPage",
                location = "/cnbdw/employee/add.jsp"
        ), @Result(
                name = "batchAddPage",
                location = "/cnbdw/employee/batchadd.jsp"
        ), @Result(
                name = "listPage",
                location = "/cnbdw/employee/list.jsp"
        ), @Result(
                name = "stay",
                location = "/cnbdw/employee/stay.jsp"
        ), @Result(
                name = "reNewStay",
                location = "/cnbdw/employee/reStay.jsp"
        ), @Result(
                name = "punch",
                location = "/cnbdw/employee/punch.jsp"
        ), @Result(
                name = "write",
                location = "/cnbdw/employee/write-card.jsp"
        ), @Result(
                name = "writing",
                location = "/cnbdw/employee/writing.jsp"
        ), @Result(
                name = "exchange",
                location = "/cnbdw/employee/exchange.jsp"
        ), @Result(
                name = "autoStayPage",
                location = "/cnbdw/employee/auto-stay.jsp"
        ), @Result(
                name = "bindPage",
                location = "/cnbdw/employee/bind.jsp"
        ), @Result(
                name = "printPage",
                location = "/cnbdw/employee/print.jsp"
        ), @Result(
                name = "empBindDevicePage",
                location = "/cnbdw/employee/empBindDevicePage.jsp"
        ), @Result(
                name = "empRelieveDevicePage",
                location = "/cnbdw/employee/empRelieveDevicePage.jsp"
        ), @Result(
                name = "deviceRelieveEmpPage",
                location = "/cnbdw/employee/deviceRelieveEmpPage.jsp"
        ), @Result(
                name = "exportPage",
                location = "/cnbdw/employee/export.jsp"
        ), @Result(
                name = "bindList",
                location = "/cnbdw/employee/bindList.jsp"
        ), @Result(
                name = "index",
                location = "index.jsp"
        ), @Result(
                name = "editPage",
                location = "/cnbdw/employee/edit.jsp"
        )}
)
public class EmployeeAction extends BaseAction implements ModelDriven<Employee> {
    private Employee employee = new Employee();
    private LogInfo logInfo = new LogInfo();
    @Autowired
    private LogInfoService logService;
    @Autowired
    private RoomService roomService;
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private BedInfoService bedInfoService;
    @Autowired
    private EmployeeRoomHistoryService employeeRoomHistoryService;
    @Autowired
    private EmployeePunchHistoryService employeePunchHistoryService;
    @Autowired
    private LevelRegionMapService levelRegionMapService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private LevelService levelService;
    @Autowired
    private EmployeeDeviceService employeeDeviceService;
    @Autowired
    private EmployeeDeviceHistoryService employeeDeviceHistoryService;
    @Autowired
    private RegionInfoService regionInfoService;

    public EmployeeAction() {
    }

    public String indexPage() {
        return "listPage";
    }

    public String toAddPage() {
        return "addPage";
    }

    public String toBatchAddPage() {
        return "batchAddPage";
    }

    public String printDatasourceList() {
        try {
            String empId = this.getRequest().getParameter("empId");
            Employee emp = (Employee)this.employeeService.selectByPrimaryKey(empId, Employee.class);
            BeanUtils.copyProperties(emp, this.getModel());
        } catch (Exception var3) {
            var3.printStackTrace();
        }

        return "printPage";
    }

    public void getRegionJSON() {
        List<Map<String, String>> list = new ArrayList();
        RegionInfoExample example = new RegionInfoExample();
        List regionList = null;

        try {
            regionList = this.regionInfoService.selectByExample(example);
        } catch (Exception var7) {
            var7.printStackTrace();
            return;
        }

        Iterator var5 = regionList.iterator();

        while(var5.hasNext()) {
            RegionInfo regionInfo = (RegionInfo)var5.next();
            Map<String, String> map = new HashMap();
            map.put("id", regionInfo.getId());
            map.put("text", regionInfo.getName());
            list.add(map);
        }

        this.writeJson(list);
    }

    public String toEditPage() {
        try {
            Employee emp = (Employee)this.employeeService.selectByPrimaryKey(this.employee.getId(), Employee.class);
            BeanUtils.copyProperties(emp, this.getModel());
        } catch (Exception var2) {
            var2.printStackTrace();
        }

        return "editPage";
    }

    public String reNewStay() {
        try {
            String empId = this.getRequest().getParameter("id");
            Employee emp = (Employee)this.employeeService.selectByPrimaryKey(empId, Employee.class);
            BedInfo bed = this.bedInfoService.selectByEmpId(empId);
            String stayTime = bed.getStayTime();
            String outTime = bed.getOutTime();
            String empName = emp.getName();
            this.getRequest().setAttribute("empId", empId);
            this.getRequest().setAttribute("stayTime", stayTime);
            this.getRequest().setAttribute("outTime", outTime);
            this.getRequest().setAttribute("empName", empName);
        } catch (Exception var7) {
            var7.printStackTrace();
        }

        return "reNewStay";
    }

    public void updateStay() {
        PageJson json = new PageJson();
        String time = DateUtil.getInstance().formatDate(new Date());

        try {
            BedInfo bed = new BedInfo();
            bed.setEmpId(this.getRequest().getParameter("empId"));
            bed.setStayTime(this.getRequest().getParameter("stayTime"));
            bed.setOutTime(this.getRequest().getParameter("outTime"));
            int i = this.bedInfoService.updateStayTime(bed);
            String name = this.employeeService.selectByName(this.getRequest().getParameter("empId"));
            BedInfo bed1 = this.bedInfoService.selectByEmpId(this.getRequest().getParameter("empId"));
            String roomName = this.roomService.selectNameById(bed1.getRoomId());
            if(i > 0) {
                this.logInfo.setUserId(RequestUtil.getSessionUserinfo().getUsername());
                this.logInfo.setId(UUID.randomUUID().toString());
                this.logInfo.setTime(time);
                this.logInfo.setMemo(name + " " + roomName + " " + bed1.getBedNo());
                this.logInfo.setFunc("入住");
                this.logInfo.setOp("续住");
                this.logInfo.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                this.logService.insert(this.logInfo);
                json.setReturnFlag(true);
                json.setReturnMsg("续住成功！请及时写卡");
            } else {
                json.setReturnFlag(false);
                json.setReturnMsg("续住失败！");
            }
        } catch (Exception var8) {
            json.setReturnFlag(false);
            json.setReturnMsg("提交出错了");
            LOG.error("获取数据失败", var8, new String[0]);
        }

        this.writeJson(json);
    }

    public void getAllDatasourceList() {
        try {
            EmployeeExample employeeExample = new EmployeeExample();
            if(StringUtils.isNotBlank(this.getRequest().getParameter("name"))) {
                employeeExample.createCriteria().andNameLike("%" + this.getRequest().getParameter("name") + "%");
            }

            if(StringUtils.isNotEmpty(this.getRequest().getParameter("cardType"))) {
                employeeExample.createCriteria().andCardTypeEqualTo(new Short(this.getRequest().getParameter("cardType")));
            }

            if(StringUtils.isNotBlank(this.getRequest().getParameter("cardNo"))) {
                employeeExample.createCriteria().andCardNoLike("%" + this.getRequest().getParameter("cardNo") + "%");
            }

            if(StringUtils.isNotBlank(this.getRequest().getParameter("company"))) {
                employeeExample.createCriteria().andCompanyLike("%" + this.getRequest().getParameter("company") + "%");
            }

            if(StringUtils.isNotBlank(this.getRequest().getParameter("start"))) {
                employeeExample.createCriteria().andUpdateTimeGreaterThanOrEqualTo(this.getRequest().getParameter("start"));
            }

            if(StringUtils.isNotBlank(this.getRequest().getParameter("end"))) {
                employeeExample.createCriteria().andUpdateTimeLessThanOrEqualTo(this.getRequest().getParameter("end"));
            }

            employeeExample.setOrderByClause("update_time desc");
            int total = this.employeeService.countByExample(employeeExample);
            com.the4man.cnbdw.utils.Page<Employee> page = new com.the4man.cnbdw.utils.Page<>();
            this.setPageProperties(page);
            this.employeeService.selectByExample(employeeExample, page);
            DataGrid d = new DataGrid();
            d.setRows(page.getData());
            d.setTotal(Long.valueOf((long)total));
            this.writeJson(d);
        } catch (Exception var5) {
            LOG.error("获取数据失败", var5, new String[0]);
        }

    }

    public void getPunchAllDatasourceList() {
        try {
            String name = this.getRequest().getParameter("ename");
            int total = this.employeeService.punchCount(name);
            com.the4man.cnbdw.utils.Page<Employee> page = new com.the4man.cnbdw.utils.Page<>();
            this.setPageProperties(page);
            List<Employee> list = this.employeeService.selectByPunch(name);
            page.setData(list);
            page.setRowCount(total);
            DataGrid d = new DataGrid();
            d.setRows(page.getData());
            d.setTotal(Long.valueOf((long)total));
            this.writeJson(d);
        } catch (Exception var6) {
            LOG.error("获取数据失败", var6, new String[0]);
        }

    }

    public void getPrintDatasourceList() {
        try {
            EmployeeExample employeeExample = new EmployeeExample();
            int total = this.employeeService.countByExample(employeeExample);
            com.the4man.cnbdw.utils.Page<Employee> page = new com.the4man.cnbdw.utils.Page<>();
            this.setPageProperties(page);
            this.employeeService.selectPrintByExample(employeeExample, page);
            DataGrid d = new DataGrid();
            d.setRows(page.getData());
            d.setTotal(Long.valueOf((long)total));
            this.writeJson(d);
        } catch (Exception var5) {
            LOG.error("获取数据失败", var5, new String[0]);
        }

    }

    public String exportDatasourceList() {
        try {
            EmployeeExample employeeExample = new EmployeeExample();
            if(StringUtils.isNotBlank(this.getRequest().getParameter("name"))) {
                employeeExample.createCriteria().andNameLike("%" + this.getRequest().getParameter("name") + "%");
            }

            employeeExample.setOrderByClause("create_time desc");
            Employee emp = new Employee();
            emp.setEmployeeList(this.employeeService.selectExByExample(employeeExample));
            BeanUtils.copyProperties(emp, this.getModel());
        } catch (Exception var3) {
            LOG.error("获取数据失败", var3, new String[0]);
        }

        return "exportPage";
    }

    public void add() {
        PageJson json = new PageJson();

        try {
            String time = DateUtil.getInstance().formatDate(new Date());
            this.employee.setId(UUID.randomUUID().toString());
            this.employee.setCreateTime(time);
            this.employee.setUpdateTime(time);
            this.employee.setCreateUser(RequestUtil.getSessionUserinfo().getUsername());
            this.employee.setUpdateUser(RequestUtil.getSessionUserinfo().getUsername());
            Short cardType = this.employee.getCardType();
            String cardNo = this.employee.getCardNo();
            String type = "";
            if(cardType.equals("1")) {
                type = "身份证";
            } else {
                type = "军官证";
            }

            List<Employee> emp = this.employeeService.selectBySfId(cardType, cardNo);
            if(emp != null && emp.size() != 0) {
                json.setReturnFlag(false);
                json.setReturnMsg("身份信息重复。");
            } else {
                this.employeeService.insert(this.employee);
                this.logInfo.setId(UUID.randomUUID().toString());
                this.logInfo.setTime(time);
                this.logInfo.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                this.logInfo.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                this.logInfo.setFunc("人员信息");
                this.logInfo.setOp("人员添加");
                this.logInfo.setMemo("姓名:" + this.employee.getName() + " 证件类型:" + type + " 证件号码:" + cardNo);
                this.logService.insert(this.logInfo);
                json.setReturnFlag(true);
                json.setReturnMsg("提交成功！");
            }
        } catch (Exception var7) {
            json.setReturnFlag(false);
            json.setReturnMsg("提交出错了");
            LOG.error("获取数据失败", var7, new String[0]);
        }

        this.writeJson(json);
    }

    public void batchAdd() {
        PageJson json = new PageJson();

        try {
            String realpath = this.getClass().getClassLoader().getResource("/").getPath();
            int endIndex = realpath.indexOf("/WEB-INF");
            realpath = realpath.substring(0, endIndex);
            File fileTmp = new File(realpath + this.employee.getEmployeeTmp());
            File filePhoto = new File(realpath + this.employee.getPhotoRes());
            List<Employee> list = Tools.readEmployeeByExcel(fileTmp);
            String photoSvPath = this.employee.getPhotoRes().substring(0, this.employee.getPhotoRes().lastIndexOf("/") + 1);
            String photoPath = realpath + photoSvPath;
            Tools.upZipFile(filePhoto, photoPath);
            int count = 0;
            List<String> ids = new ArrayList();
            List<Employee> repeatList = new ArrayList();
            Iterator var13 = list.iterator();

            while(true) {
                Employee info;
                while(var13.hasNext()) {
                    info = (Employee)var13.next();
                    String cardNo = info.getCardNo();
                    Short cardType = info.getCardType();
                    int ct = this.employeeService.countByCard(cardType, cardNo);
                    if(ct > 0) {
                        repeatList.add(info);
                    } else {
                        String time = DateUtil.getInstance().formatDate(new Date());
                        String id = UUID.randomUUID().toString();
                        ids.add(id);
                        if(info.getPhoto() != null && !"".equals(info.getPhoto())) {
                            info.setPhoto(photoSvPath + info.getPhoto());
                        } else {
                            info.setPhoto("/images/headpicture/none.png");
                        }

                        info.setRegionId("6ebf01dd-c913-45b4-92c1-c5f134f52ae1");
                        info.setId(id);
                        String level = info.getLevel();
                        String emplev = this.levelService.selectLevelId(new Short(level));
                        info.setLevel(emplev);
                        info.setCreateTime(time);
                        info.setUpdateTime(time);
                        info.setCreateUser(RequestUtil.getSessionUserinfo().getUsername());
                        info.setUpdateUser(RequestUtil.getSessionUserinfo().getUsername());
                        info.setPunch(Short.valueOf((short) 0));
                        int c = this.employeeService.insert(info);
                        this.logInfo.setId(UUID.randomUUID().toString());
                        this.logInfo.setTime(time);
                        this.logInfo.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                        this.logInfo.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                        this.logInfo.setFunc("人员信息");
                        this.logInfo.setOp("人员批量添加");
                        this.logInfo.setMemo("姓名:" + info.getName() + " 证件类型:" + info.getCardType() + " 证件号码:" + info.getCardNo());
                        this.logService.insert(this.logInfo);
                        if(c > 0) {
                            ++count;
                        }
                    }
                }

                var13 = repeatList.iterator();

                while(var13.hasNext()) {
                    info = (Employee)var13.next();
                    list.remove(info);
                }

                var13 = list.iterator();

                while(var13.hasNext()) {
                    info = (Employee)var13.next();
                    this.getRequest().setAttribute("id", info.getId());
                    this.getRequest().setAttribute("punch", "0");
                }

                json.setReturnFlag(true);
                json.setReturnMsg("成功导入" + count + "条数据," + repeatList.size() + "条重复数据");
                json.setObj(Integer.valueOf(ids.size()));
                break;
            }
        } catch (Exception var22) {
            var22.printStackTrace();
            json.setReturnFlag(false);
            json.setReturnMsg("提交出错了");
        }

        this.writeJson(json);
    }

    public void employeeManage() {
        PageJson json = new PageJson();

        try {
            String id = this.getRequest().getParameter("ids");
            List<Employee> repeatList = (List)this.getSession().getAttribute("repeatList");
            Iterator var5 = repeatList.iterator();

            while(var5.hasNext()) {
                Employee info = (Employee)var5.next();
                if(id.equals(info.getId())) {
                    EmployeeExample example = new EmployeeExample();
                    example.createCriteria().andCardNoEqualTo(info.getCardNo());
                    List<Employee> employees = this.employeeService.selectByExample(example);
                    if(employees != null && employees.size() > 0) {
                        info.setId(((Employee)employees.get(0)).getId());
                    }

                    this.employeeService.updateByPrimaryKey(info);
                }
            }

            json.setReturnFlag(true);
            json.setReturnMsg("成功导入成功");
        } catch (Exception var8) {
            var8.printStackTrace();
            json.setReturnFlag(false);
            json.setReturnMsg("提交出错了");
        }

        this.writeJson(json);
    }

    public void update() {
        PageJson json = new PageJson();

        try {
            Object o = this.employeeService.selectByPrimaryKey(this.employee.getId(), Employee.class);
            if(o == null) {
                json.setReturnFlag(false);
                json.setReturnMsg("修改的记录不存在");
                this.writeJson(json);
                return;
            }

            Short cardType = this.employee.getCardType();
            String cardNo = this.employee.getCardNo();
            String id = this.employee.getId();
            Employee emp = this.employeeService.selectMBySfId(id, cardType, cardNo);
            if(emp == null) {
                this.employee.setUpdateTime(DateUtil.getInstance().formatDate(new Date()));
                this.employee.setUpdateUser(RequestUtil.getSessionUserinfo().getUsername());
                BeanUtils.copyProperties(this.employee, o, new String[]{"createTime", "createUser"});
                this.employeeService.updateByPrimaryKey(this.employee);
                this.logInfo.setId(UUID.randomUUID().toString());
                this.logInfo.setTime(DateUtil.getInstance().formatDate(new Date()));
                this.logInfo.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                this.logInfo.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                this.logInfo.setFunc("人员信息");
                this.logInfo.setOp("人员修改");
                this.logInfo.setMemo("姓名:" + this.employee.getName() + " 证件类型:" + this.employee.getCardType() + " 证件号码:" + this.employee.getCardNo());
                this.logService.insert(this.logInfo);
                json.setReturnFlag(true);
                json.setReturnMsg("提交成功！");
            } else {
                json.setReturnFlag(false);
                json.setReturnMsg("身份信息重复。");
            }
        } catch (Exception var7) {
            json.setReturnFlag(false);
            json.setReturnMsg("提交出错了");
            LOG.error("获取数据失败", var7, new String[0]);
        }

        this.writeJson(json);
    }

    public String executeModifyResult() {
        try {
            Object instance = this.employeeService.selectByPrimaryKey(this.employee.getId(), Employee.class);
            this.getRequest().setAttribute("instance", instance);
        } catch (Exception var2) {
            LOG.error("获取数据失败", var2, new String[0]);
        }

        return "modifyPage";
    }

    public void delete() {
        PageJson json = new PageJson();

        try {
            String ids = this.getRequest().getParameter("ids");
            EmployeeDeviceExample example = new EmployeeDeviceExample();
            String[] id = ids.split(",");

            for(int j = 0; j < id.length; ++j) {
                example.createCriteria().andEmpIdEqualTo(id[j]);
                int bindCount = this.employeeDeviceService.countByExample(example);
                BedInfo b = this.bedInfoService.selectByEmpId(id[j]);
                if(bindCount <= 0 && b == null) {
                    Employee emp = (Employee)this.employeeService.selectByPrimaryKey(id[j], Employee.class);
                    int i = this.employeeService.deleteByPrimaryKey(id[j], Employee.class);
                    if(i > 0) {
                        this.logInfo.setId(UUID.randomUUID().toString());
                        this.logInfo.setTime(DateUtil.getInstance().formatDate(new Date()));
                        this.logInfo.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                        this.logInfo.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                        this.logInfo.setFunc("人员信息");
                        this.logInfo.setOp("人员删除");
                        this.logInfo.setMemo("姓名:" + emp.getName() + " 证件类型:" + emp.getCardType() + " 证件号码:" + emp.getCardNo());
                        this.logService.insert(this.logInfo);
                        json.setReturnMsg("删除人员成功！");
                        json.setReturnFlag(true);
                    } else {
                        json.setReturnMsg("删除人员失败！");
                        json.setReturnFlag(false);
                    }
                } else {
                    json.setReturnMsg("未完全删除！！请检查选择的人员是否退房，是否解绑所有设备！！");
                    json.setReturnFlag(false);
                }
            }
        } catch (Exception var10) {
            LOG.error("批量删除人员失败！", var10, new String[0]);
            json.setReturnMsg("删除人员失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public void verify() {
        PageJson json = new PageJson();
        this.writeJson(json);
    }

    public String exchangePage() {
        return "exchange";
    }

    public String stayPage() {
        int stayCount = this.employeeService.selectStayCount();
        this.getRequest().setAttribute("stayCount", Integer.valueOf(stayCount));
        return "stay";
    }

    public String bindListPage() {
        return "bindList";
    }

    public String autoStayPage() {
        try {
            String employeeId = this.employee.getId();
            String stayTime = this.getRequest().getParameter("stayTime");
            String outTime = this.getRequest().getParameter("outTime");
            Employee emp = (Employee)this.employeeService.selectByPrimaryKey(employeeId, Employee.class);
            this.getRequest().setAttribute("emp", emp);
            this.getRequest().setAttribute("stayTime", stayTime);
            this.getRequest().setAttribute("outTime", outTime);
        } catch (Exception var5) {
            LOG.error("获取数据失败", var5, new String[0]);
        }

        return "autoStayPage";
    }

    public void checkedOut() {
        PageJson json = new PageJson();

        try {
            label47: {
                String bedId = this.getRequest().getParameter("bedId");
                String empId = this.getRequest().getParameter("empId");
                String roomId = this.getRequest().getParameter("roomId");
                if(!StringUtils.isBlank(bedId) && !StringUtils.isBlank(empId) && !StringUtils.isBlank(roomId)) {
                    Employee emp = (Employee)this.employeeService.selectByPrimaryKey(empId, Employee.class);
                    BedInfo bed = (BedInfo)this.bedInfoService.selectByPrimaryKey(bedId, BedInfo.class);
                    Room room = (Room)this.roomService.selectByPrimaryKey(roomId, Room.class);
                    if(emp != null && bed != null && room != null) {
                        BedInfoExample bedInfoExample = new BedInfoExample();
                        bedInfoExample.createCriteria().andEmpIdEqualTo(empId);
                        List list = this.bedInfoService.selectByExample(bedInfoExample);
                        if(list != null && !list.isEmpty()) {
                            BedInfo bedInfo = new BedInfo();
                            bedInfo.setId(bedId);
                            bedInfo.setEmpId("");
                            bedInfo.setStayTime("");
                            bedInfo.setOutTime("");
                            this.bedInfoService.updateByPrimaryKeySelective(bedInfo);
                            EmployeeRoomHistory erh = new EmployeeRoomHistory();
                            erh.setId(UUID.randomUUID().toString());
                            erh.setEmpId(empId);
                            erh.setArea(room.getArea());
                            erh.setDeck(room.getDeck());
                            erh.setType(room.getType());
                            erh.setRoomId(room.getId());
                            erh.setProps(room.getProps());
                            erh.setOrigRoomId("");
                            erh.setOperateType(Short.valueOf("1"));
                            erh.setBedNo(bed.getId());
                            erh.setReason("退房");
                            String time = DateUtil.getInstance().formatDate(new Date());
                            erh.setCreateTime(time);
                            erh.setUpdateTime(time);
                            erh.setCreateUser(RequestUtil.getSessionUserinfo().getUsername());
                            erh.setUpdateUser(RequestUtil.getSessionUserinfo().getUsername());
                            this.employeeRoomHistoryService.insert(erh);
                            String name = this.employeeService.selectByName(empId);
                            this.logInfo.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                            this.logInfo.setId(UUID.randomUUID().toString());
                            this.logInfo.setTime(time);
                            this.logInfo.setMemo(name + " " + room.getRoomNo() + " " + bed.getBedNo());
                            this.logInfo.setFunc("入住");
                            this.logInfo.setOp("退房");
                            this.logInfo.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                            this.logService.insert(this.logInfo);
                            json.setReturnMsg("退房成功！");
                            json.setReturnFlag(true);
                            break label47;
                        }

                        json.setReturnMsg("人员未入住，请勿重复操作！");
                        json.setReturnFlag(false);
                        this.writeJson(json);
                        return;
                    }

                    json.setReturnMsg("无法找到对应的数据！");
                    json.setReturnFlag(false);
                    this.writeJson(json);
                    return;
                }

                json.setReturnMsg("参数不完整，请重试！");
                json.setReturnFlag(false);
                this.writeJson(json);
                return;
            }
        } catch (Exception var14) {
            LOG.error("退房失败！", var14, new String[0]);
            json.setReturnMsg("退房失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public void stay() {
        PageJson json = new PageJson();

        try {
            label91: {
                String bedId = this.getRequest().getParameter("bedId");
                String nowBedId = this.getRequest().getParameter("nowBedId");
                String empId = this.getRequest().getParameter("empId");
                String roomId = this.getRequest().getParameter("roomId");
                String nowRoomId = this.getRequest().getParameter("nowRoomId");
                String startStay = this.getRequest().getParameter("startStay");
                String endStay = this.getRequest().getParameter("endStay");
                if("true".equals(this.getRequest().getParameter("exchange")) && (StringUtils.isBlank(nowBedId) || StringUtils.isBlank(nowRoomId))) {
                    json.setReturnMsg("参数不完整，请重试！");
                    json.setReturnFlag(false);
                    this.writeJson(json);
                    return;
                }

                if(!StringUtils.isBlank(bedId) && !StringUtils.isBlank(empId) && !StringUtils.isBlank(roomId)) {
                    Employee emp = (Employee)this.employeeService.selectByPrimaryKey(empId, Employee.class);
                    BedInfo bed = (BedInfo)this.bedInfoService.selectByPrimaryKey(bedId, BedInfo.class);
                    Room room = (Room)this.roomService.selectByPrimaryKey(roomId, Room.class);
                    if(emp != null && bed != null && room != null) {
                        BedInfo nowBed = null;
                        Room nowRoom = null;
                        if(nowBedId != null && nowRoomId != null) {
                            nowBed = (BedInfo)this.bedInfoService.selectByPrimaryKey(nowBedId, BedInfo.class);
                            nowRoom = (Room)this.roomService.selectByPrimaryKey(nowRoomId, Room.class);
                            if("true".equals(this.getRequest().getParameter("exchange")) && (nowRoom == null || nowBed == null)) {
                                json.setReturnMsg("无法找到对应的数据！");
                                json.setReturnFlag(false);
                                this.writeJson(json);
                                return;
                            }
                        }

                        BedInfoExample bedInfoExample = new BedInfoExample();
                        bedInfoExample.createCriteria().andEmpIdEqualTo(empId);
                        List list = this.bedInfoService.selectByExample(bedInfoExample);
                        if(!"true".equals(this.getRequest().getParameter("exchange")) && list != null && !list.isEmpty()) {
                            json.setReturnMsg("人员已经入住，请勿重复操作！");
                            json.setReturnFlag(false);
                            this.writeJson(json);
                            return;
                        }

                        EmployeeRoomHistory erh;
                        String time;
                        LogInfo logInfo1;
                        if("true".equals(this.getRequest().getParameter("exchange"))) {
                            EmployeeRoomHistory erhlist = (EmployeeRoomHistory)this.employeeRoomHistoryService.selectByPrimaryKey(nowBedId, EmployeeRoomHistory.class);
                            if(erhlist == null) {
                                erh = new EmployeeRoomHistory();
                                erh.setId(UUID.randomUUID().toString());
                                erh.setEmpId(empId);
                                erh.setArea(room.getArea());
                                erh.setDeck(room.getDeck());
                                erh.setType(room.getType());
                                erh.setRoomId(room.getId());
                                erh.setProps(room.getProps());
                                erh.setOrigRoomId(nowRoomId);
                                erh.setOrigBedNo(nowBedId);
                                erh.setOperateType(Short.valueOf("2"));
                                erh.setBedNo(bed.getId());
                                erh.setReason("换房");
                                erh.setCreateTime(DateUtil.getInstance().formatDate(new Date()));
                                erh.setUpdateTime(DateUtil.getInstance().formatDate(new Date()));
                                erh.setCreateUser(RequestUtil.getSessionUserinfo().getUsername());
                                erh.setUpdateUser(RequestUtil.getSessionUserinfo().getUsername());
                                this.employeeRoomHistoryService.insert(erh);
                            }

                            erhlist.setId(UUID.randomUUID().toString());
                            erhlist.setOperateType(Short.valueOf("1"));
                            erhlist.setReason("退房");
                            String time1 = DateUtil.getInstance().formatDate(new Date());
                            erhlist.setCreateTime(time1);
                            erhlist.setUpdateTime(time1);
                            erhlist.setCreateUser(RequestUtil.getSessionUserinfo().getUsername());
                            erhlist.setUpdateUser(RequestUtil.getSessionUserinfo().getUsername());
                            this.employeeRoomHistoryService.insert(erhlist);
                            time = DateUtil.getInstance().formatDate(new Date());
                            nowBed.setEmpId("");
                            nowBed.setStayTime("");
                            nowBed.setOutTime("");
                            this.bedInfoService.updateByPrimaryKey(nowBed);
                            logInfo1 = new LogInfo();
                            logInfo1.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                            logInfo1.setId(UUID.randomUUID().toString());
                            logInfo1.setTime(time);
                            logInfo1.setMemo(emp.getName() + " " + room.getRoomNo() + "房" + nowBed.getBedNo() + "床");
                            logInfo1.setFunc("入住");
                            logInfo1.setOp("换房退房");
                            logInfo1.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                            this.logService.insert(logInfo1);
                            bed.setEmpId(empId);
                            bed.setStayTime(startStay);
                            bed.setOutTime(endStay);
                            this.bedInfoService.updateByPrimaryKeySelective(bed);
                            this.logInfo.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                            this.logInfo.setId(UUID.randomUUID().toString());
                            this.logInfo.setTime(time);
                            this.logInfo.setMemo(emp.getName() + " " + room.getRoomNo() + " " + bed.getBedNo());
                            this.logInfo.setFunc("入住");
                            this.logInfo.setOp("换房入住");
                            this.logInfo.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                            this.logService.insert(this.logInfo);
                            /*EmployeeRoomHistory */erh = new EmployeeRoomHistory();
                            erh.setId(UUID.randomUUID().toString());
                            erh.setEmpId(empId);
                            erh.setArea(room.getArea());
                            erh.setDeck(room.getDeck());
                            erh.setType(room.getType());
                            erh.setRoomId(room.getId());
                            erh.setProps(room.getProps());
                            erh.setOrigRoomId(nowRoomId);
                            erh.setOrigBedNo(nowBedId);
                            erh.setOperateType(Short.valueOf("2"));
                            erh.setBedNo(bed.getId());
                            erh.setReason("换房");
                            erh.setCreateTime(time);
                            erh.setUpdateTime(time);
                            erh.setCreateUser(RequestUtil.getSessionUserinfo().getUsername());
                            erh.setUpdateUser(RequestUtil.getSessionUserinfo().getUsername());
                            this.employeeRoomHistoryService.insert(erh);
                        } else {
                            BedInfo bedInfo = new BedInfo();
                            bedInfo.setId(bedId);
                            bedInfo.setEmpId(empId);
                            bedInfo.setStayTime(startStay);
                            bedInfo.setOutTime(endStay);
                            this.bedInfoService.updateByPrimaryKeySelective(bedInfo);
                            erh = new EmployeeRoomHistory();
                            erh.setId(UUID.randomUUID().toString());
                            erh.setEmpId(empId);
                            erh.setArea(room.getArea());
                            erh.setDeck(room.getDeck());
                            erh.setType(room.getType());
                            erh.setRoomId(room.getId());
                            erh.setProps(room.getProps());
                            erh.setOrigRoomId("");
                            erh.setOperateType(Short.valueOf("0"));
                            erh.setBedNo(bed.getId());
                            erh.setReason("入住");
                            time = DateUtil.getInstance().formatDate(new Date());
                            erh.setCreateTime(startStay);
                            erh.setUpdateTime(time);
                            erh.setCreateUser(RequestUtil.getSessionUserinfo().getUsername());
                            erh.setUpdateUser(RequestUtil.getSessionUserinfo().getUsername());
                            this.employeeRoomHistoryService.insert(erh);
                            logInfo1 = new LogInfo();
                            logInfo1.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                            logInfo1.setId(UUID.randomUUID().toString());
                            logInfo1.setTime(time);
                            logInfo1.setMemo(emp.getName() + " " + room.getRoomNo() + " 房" + bed.getBedNo() + "床");
                            logInfo1.setFunc("入住");
                            logInfo1.setOp("入住");
                            logInfo1.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                            this.logService.insert(logInfo1);
                        }

                        json.setReturnMsg("入住成功！");
                        json.setReturnFlag(true);
                        break label91;
                    }

                    json.setReturnMsg("无法找到对应的数据！");
                    json.setReturnFlag(false);
                    this.writeJson(json);
                    return;
                }

                json.setReturnMsg("参数不完整，请重试！");
                json.setReturnFlag(false);
                this.writeJson(json);
                return;
            }
        } catch (Exception var21) {
            LOG.error("入住失败！", var21, new String[0]);
            json.setReturnMsg("入住失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public String bindPage() {
        return "bindPage";
    }

    public String empBindDevicePage() {
        String empId = this.getRequest().getParameter("empId");
        String cardNum = this.getRequest().getParameter("cardNum");
        this.getRequest().setAttribute("empId", empId);
        this.getRequest().setAttribute("cardNum", cardNum);
        return "empBindDevicePage";
    }

    public void bindDeviceDatasource() {
        try {
            DeviceExample deviceExample = new DeviceExample();
            DeviceExampleBase.Criteria cc = deviceExample.createCriteria();
            cc.andNotBindDevice();
            HttpServletRequest req = this.getRequest();
            String cardNum = req.getParameter("deviceNo");
            String hardwareNo = req.getParameter("cardNum");
            String deviceType = req.getParameter("deviceType");
            if(StringUtils.isNotEmpty(cardNum)) {
                cc.andCardNumLike("%" + cardNum + "%");
            }

            if(StringUtils.isNotEmpty(hardwareNo)) {
                cc.andHardwareNoLike("%" + hardwareNo + "%");
            }

            if(StringUtils.isNotEmpty(deviceType)) {
                cc.andDeviceTypeEqualTo(deviceType);
            }

            cc.andDeviceStateEqualTo(Integer.valueOf(1));
            List<Device> list = this.deviceService.selectByExample(deviceExample);
            DataGrid d = new DataGrid();
            d.setRows(list);
            this.writeJson(d);
        } catch (Exception var9) {
            LOG.error("获取数据失败", var9, new String[0]);
        }

    }

    public String empRelieveDevicePage() {
        String empId = this.getRequest().getParameter("empId");
        this.getRequest().setAttribute("emp", empId);
        return "empRelieveDevicePage";
    }

    public String deviceRelieveEmpPage() {
        String cardSn = this.getRequest().getParameter("cardSn");
        DeviceExample deviceExample = new DeviceExample();
        DeviceExampleBase.Criteria cc = deviceExample.createCriteria();
        cc.andHardwareNoEqualTo(cardSn);

        try {
            List<Device> list = this.deviceService.selectByExample(deviceExample);
            String deviceId = ((Device)list.get(0)).getId();
            String empId = this.deviceService.selecEmpId(deviceId);
            String empName = this.employeeService.selectEmpName(empId);
            this.getRequest().setAttribute("deviceId", deviceId);
            this.getRequest().setAttribute("empId", empId);
            this.getRequest().setAttribute("empName", empName);
        } catch (Exception var8) {
            LOG.error("获取数据失败", var8, new String[0]);
        }

        return "deviceRelieveEmpPage";
    }

    public void removeDeviceDatasource() {
        try {
            HttpServletRequest req = this.getRequest();
            String empId = req.getParameter("empId");
            DeviceExample deviceExample = new DeviceExample();
            DeviceExampleBase.Criteria cc = deviceExample.createCriteria();
            cc.andExistBindDevice(empId);
            List<Device> list = this.deviceService.selectByExample(deviceExample);
            DataGrid d = new DataGrid();
            d.setRows(list);
            this.writeJson(d);
        } catch (Exception var7) {
            LOG.error("获取数据失败", var7, new String[0]);
        }

    }

    public void removeEmpDeviceDatasource() {
        try {
            HttpServletRequest req = this.getRequest();
            String empId = req.getParameter("empId");
            String deviceId = req.getParameter("deviceId");
            DeviceExample deviceExample = new DeviceExample();
            DeviceExampleBase.Criteria cc = deviceExample.createCriteria();
            cc.andExistBindDevice(empId);
            cc.andIdEqualTo(deviceId);
            List<Device> list = this.deviceService.selectByExample(deviceExample);
            DataGrid d = new DataGrid();
            d.setRows(list);
            this.writeJson(d);
        } catch (Exception var8) {
            LOG.error("获取数据失败", var8, new String[0]);
        }

    }

    public void doBindDevice() {
        HttpServletRequest request = this.getRequest();
        String ids = request.getParameter("ids");
        String empId = request.getParameter("empId");
        String[] idArray = ids.split(",");
        PageJson resultJson = new PageJson();
        String time = DateUtil.getInstance().formatDate(new Date());

        try {
            int row = 0;
            String[] var11 = idArray;
            int var10 = idArray.length;

            for(int var9 = 0; var9 < var10; ++var9) {
                String id = var11[var9];
                EmployeeDevice edRel = new EmployeeDevice();
                edRel.setId(GenUtil.genUUID());
                edRel.setDevId(id);
                edRel.setEmpId(empId);
                row += this.employeeDeviceService.insert(edRel);
                EmployeeDeviceHistory edh = new EmployeeDeviceHistory();
                String time1 = DateUtil.getInstance().formatDate(new Date());
                edh.setId(GenUtil.genUUID());
                edh.setEmpId(empId);
                edh.setDevId(id);
                edh.setRecordTime(time1);
                edh.setLogoffTime("");
                this.employeeDeviceHistoryService.insert(edh);
                LogInfo logInfo1 = new LogInfo();
                String empName = this.employeeService.selectByName(empId);
                String deviceName = this.deviceService.selectNameById(id);
                logInfo1.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                logInfo1.setId(UUID.randomUUID().toString());
                logInfo1.setTime(time);
                logInfo1.setMemo(empName + "绑定" + deviceName);
                logInfo1.setFunc("人员信息");
                logInfo1.setOp("设备绑定");
                logInfo1.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                this.logService.insert(logInfo1);
            }

            if(row > 0) {
                Employee emp = (Employee)this.employeeService.selectByPrimaryKey(empId, Employee.class);
                String time2 = DateUtil.getInstance().formatDate(new Date());
                emp.setPunch(Short.valueOf("0"));
                emp.setPunchTime("");
                this.employeeService.updateByPrimaryKey(emp);
                EmployeePunchHistory eph = new EmployeePunchHistory();
                eph.setId(UUID.randomUUID().toString());
                eph.setEmpId(empId);
                eph.setPunchTime(time2);
                eph.setPunch(Short.valueOf("0"));
                eph.setOperateId(RequestUtil.getSessionUserinfo().getUserid());
                eph.setCardNum("");
                eph.setPunchMachNo("");
                this.employeePunchHistoryService.insert(eph);
                resultJson.setReturnFlag(true);
                resultJson.setReturnMsg("绑定成功!");
            }
        } catch (Exception var18) {
            var18.printStackTrace();
            resultJson.setReturnMsg("绑定失败，服务端错误!");
        }

        this.writeJson(resultJson);
    }

    public void doRelieveDevice() {
        HttpServletRequest request = this.getRequest();
        String ids = request.getParameter("ids");
        String empId = request.getParameter("empId");
        String reason = request.getParameter("reason");
        String time1 = DateUtil.getInstance().formatDate(new Date());
        String[] idArray = ids.split(",");
        PageJson resultJson = new PageJson();

        try {
            int row = 0;
            String[] var12 = idArray;
            int var11 = idArray.length;

            for(int var10 = 0; var10 < var11; ++var10) {
                String id = var12[var10];
                EmployeeDeviceExample example = new EmployeeDeviceExample();
                EmployeeDeviceExampleBase.Criteria cc = example.createCriteria();
                cc.andEmpIdEqualTo(empId);
                cc.andDevIdEqualTo(id);
                row += this.employeeDeviceService.deleteByExample(example);
                String empName = this.employeeService.selectByName(empId);
                String deviceName = this.deviceService.selectNameById(id);
                LogInfo logInfo1 = new LogInfo();
                logInfo1.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                logInfo1.setId(UUID.randomUUID().toString());
                logInfo1.setTime(time1);
                logInfo1.setMemo(empName + "解绑" + deviceName);
                logInfo1.setFunc("人员信息");
                logInfo1.setOp("设备解绑");
                logInfo1.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                this.logService.insert(logInfo1);
                EmployeeDeviceHistory edh = new EmployeeDeviceHistory();
                edh.setDevId(id);
                edh.setOffReason(reason);
                edh.setLogoffTime(time1);
                this.employeeDeviceHistoryService.updateByPrimaryKey(edh);
            }

            if(row > 0) {
                resultJson.setReturnFlag(true);
                resultJson.setReturnMsg("解绑成功!");
            }
        } catch (Exception var19) {
            var19.printStackTrace();
            resultJson.setReturnMsg("解绑失败，服务端错误!");
        }

        this.writeJson(resultJson);
    }

    public void clearBindDevice() {
        HttpServletRequest request = this.getRequest();
        String empId = request.getParameter("empId");
        PageJson resultJson = new PageJson();
        EmployeeDeviceExample example = new EmployeeDeviceExample();
        EmployeeDeviceExampleBase.Criteria cc = example.createCriteria();
        cc.andEmpIdEqualTo(empId);

        try {
            int row = 0;
            row = row + this.employeeDeviceService.deleteByExample(example);
            if(row > 0) {
                resultJson.setReturnFlag(true);
                resultJson.setReturnMsg("清除成功!");
            }
        } catch (Exception var7) {
            var7.printStackTrace();
            resultJson.setReturnMsg("清除失败，服务端错误!");
        }

        this.writeJson(resultJson);
    }

    public void stayDatasource() {
        try {
            EmployeeExample employeeExample = new EmployeeExample();
            if(StringUtils.isNotBlank(this.getRequest().getParameter("name"))) {
                employeeExample.createCriteria().andNameLike("%" + this.getRequest().getParameter("name") + "%");
            }

            if(StringUtils.isNotBlank(this.getRequest().getParameter("ename"))) {
                employeeExample.createCriteria().andNameLike("%" + this.getRequest().getParameter("ename") + "%");
            }

            if(StringUtils.isNotEmpty(this.getRequest().getParameter("cardType"))) {
                employeeExample.createCriteria().andCardTypeEqualTo(new Short(this.getRequest().getParameter("cardType")));
            }

            if(StringUtils.isNotEmpty(this.getRequest().getParameter("empType"))) {
                employeeExample.createCriteria().andLevelEqualTo(this.getRequest().getParameter("empType"));
            }

            if(StringUtils.isNotBlank(this.getRequest().getParameter("cardNo"))) {
                employeeExample.createCriteria().andCardNoLike("%" + this.getRequest().getParameter("cardNo") + "%");
            }

            if(StringUtils.isNotBlank(this.getRequest().getParameter("company"))) {
                employeeExample.createCriteria().andCompanyLike("%" + this.getRequest().getParameter("company") + "%");
            }

            if(StringUtils.isNotBlank(this.getRequest().getParameter("start"))) {
                employeeExample.createCriteria().andUpdateTimeGreaterThanOrEqualTo(this.getRequest().getParameter("start"));
            }

            if(StringUtils.isNotBlank(this.getRequest().getParameter("end"))) {
                employeeExample.createCriteria().andUpdateTimeLessThanOrEqualTo(this.getRequest().getParameter("end"));
            }

            if(StringUtils.isNotBlank(this.getRequest().getParameter("ifBangDevice"))) {
                int aa = Integer.parseInt(this.getRequest().getParameter("ifBangDevice"));
                if(aa == 0) {
                    employeeExample.setIfBandDevice(" emp.id  in (select e.id from employee e join employee_device ed on e.id=ed.emp_id)");
                } else if(aa == 1) {
                    employeeExample.setIfBandDevice(" emp.id not in (select e.id from employee e join employee_device ed on e.id=ed.emp_id)");
                }
            }

            employeeExample.setOrderByClause("create_time desc");
            com.the4man.cnbdw.utils.Page<Employee> page = new com.the4man.cnbdw.utils.Page<>();
            this.setPageProperties(page);
            this.employeeService.selectStayByExample(employeeExample, page);
            DataGrid d = new DataGrid();
            d.setRows(page.getData());
            d.setTotal(Long.valueOf((long)page.getRowCount()));
            this.writeJson(d);
        } catch (Exception var4) {
            LOG.error("获取数据失败", var4, new String[0]);
        }

    }

    public void stayedDatasource() {
        try {
            EmployeeExample employeeExample = new EmployeeExample();
            if(StringUtils.isNotBlank(this.getRequest().getParameter("name"))) {
                employeeExample.createCriteria().andNameLike("%" + this.getRequest().getParameter("name") + "%");
            }

            if(StringUtils.isNotBlank(this.getRequest().getParameter("endOutTime"))) {
                employeeExample.setLimitOutTime("where bed.out_time <='" + this.getRequest().getParameter("endOutTime") + " 23:59:59'");
            }

            employeeExample.setOrderByClause("update_time desc");
            com.the4man.cnbdw.utils.Page<Employee> page = new com.the4man.cnbdw.utils.Page<>();
            this.setPageProperties(page);
            this.employeeService.selectStayedByExample(employeeExample, page);
            DataGrid d = new DataGrid();
            d.setRows(page.getData());
            d.setTotal(Long.valueOf((long)page.getRowCount()));
            this.writeJson(d);
        } catch (Exception var4) {
            LOG.error("获取数据失败", var4, new String[0]);
        }

    }

    public String writeCard() {
        return "write";
    }

    public String writing() {
        try {
            Set<String> doorNos = new HashSet();
            Set<String> locked = new HashSet();
            Set<String> stayTime = new HashSet();
            Set<String> outTime = new HashSet();
            BedInfoExample bedInfoExample = new BedInfoExample();
            bedInfoExample.createCriteria().andEmpIdEqualTo(this.employee.getId());
            String empId = this.employee.getId();
            List list = this.bedInfoService.selectFullByExample(bedInfoExample);
            if(list != null && !list.isEmpty()) {
                Iterator var9 = list.iterator();

                while(var9.hasNext()) {
                    Object o = var9.next();
                    BedInfo bed = (BedInfo)o;
                    if(bed.getRoom() != null) {
                        doorNos.add(bed.getRoom().getDoorNo());
                        locked.add(bed.getRoom().getLocked());
                        stayTime.add(bed.getStayTime());
                        outTime.add(bed.getOutTime());
                    }
                }
            }

            Employee emp = (Employee)this.employeeService.selectByPrimaryKey(this.employee.getId(), Employee.class);
            String level = emp.getLevel();
            LevelRegionMapExample lrExample = new LevelRegionMapExample();
            lrExample.createCriteria().andLidEqualTo(level);
            List<LevelRegionMap> lrList = this.levelRegionMapService.selectByExample(lrExample);
            if(lrList != null && !lrList.isEmpty()) {
                ArrayList<String> areaIds = new ArrayList();
                Iterator var14 = lrList.iterator();

                while(var14.hasNext()) {
                    LevelRegionMap levelRegionMap = (LevelRegionMap)var14.next();
                    areaIds.add(levelRegionMap.getRid());
                }

                RoomExample roomExample = new RoomExample();
                roomExample.createCriteria().andAreaIn(areaIds);
                List<Room> rooms = this.roomService.selectByExample(roomExample);
                if(rooms != null && !rooms.isEmpty()) {
                    Iterator var16 = rooms.iterator();

                    while(var16.hasNext()) {
                        Room room = (Room)var16.next();
                        doorNos.add(room.getDoorNo());
                        locked.add(room.getLocked());
                    }
                }
            }

            this.getRequest().setAttribute("doorNos", StringUtils.join(doorNos, ","));
            this.getRequest().setAttribute("locked", StringUtils.join(locked, ","));
            this.getRequest().setAttribute("empId", empId);
            this.getRequest().setAttribute("stayTime", StringUtils.join(stayTime, ","));
            this.getRequest().setAttribute("outTime", StringUtils.join(outTime, ","));
        } catch (Exception var17) {
            LOG.error("获取数据失败", var17, new String[0]);
        }

        return "writing";
    }

    public String punchPage() {
        int punchCount = this.employeeService.selectPunchCount();
        int noPunchCount = this.employeeService.selectNoPunchCount();
        this.getRequest().setAttribute("punchCount", Integer.valueOf(punchCount));
        this.getRequest().setAttribute("noPunchCount", Integer.valueOf(noPunchCount));
        return "punch";
    }

    public void startMonitor() {
        PageJson json = new PageJson();

        try {
            String id = this.getRequest().getParameter("id");
            int i = this.employeeService.updateStartMonitor(id);
            String time1 = DateUtil.getInstance().formatDate(new Date());
            String empName = this.employeeService.selectByName(id);
            if(i > 0) {
                LogInfo logInfo1 = new LogInfo();
                logInfo1.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                logInfo1.setId(UUID.randomUUID().toString());
                logInfo1.setTime(time1);
                logInfo1.setMemo("开启监视" + empName + "上下船");
                logInfo1.setFunc("上下船");
                logInfo1.setOp("上下船监视");
                logInfo1.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                this.logService.insert(logInfo1);
                json.setReturnMsg("启动监视人员成功！");
                json.setReturnFlag(true);
            } else {
                json.setReturnMsg("启动监视人员失败！");
                json.setReturnFlag(false);
            }
        } catch (Exception var7) {
            LOG.error("启动监视人员失败！", var7, new String[0]);
            json.setReturnMsg("启动监视人员失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public void updateStayTime() {
        PageJson json = new PageJson();

        try {
            String empId = this.getRequest().getParameter("empId");
            String stayTime = this.getRequest().getParameter("stayTime");
            String outTime = this.getRequest().getParameter("outTime");
            BedInfo bed = new BedInfo();
            bed.setEmpId(empId);
            bed.setStayTime(stayTime);
            bed.setOutTime(outTime);
            this.bedInfoService.updateStayTime(bed);
        } catch (Exception var7) {
            LOG.error("入住确认失败！", var7, new String[0]);
            json.setReturnMsg("入住确认失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public void endMonitor() {
        PageJson json = new PageJson();

        try {
            String id = this.getRequest().getParameter("id");
            int i = this.employeeService.updateEndMonitor(id);
            if(i > 0) {
                String time1 = DateUtil.getInstance().formatDate(new Date());
                String empName = this.employeeService.selectByName(id);
                LogInfo logInfo1 = new LogInfo();
                logInfo1.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                logInfo1.setId(UUID.randomUUID().toString());
                logInfo1.setTime(time1);
                logInfo1.setMemo("关闭监视" + empName + "上下船");
                logInfo1.setFunc("上下船");
                logInfo1.setOp("上下船监视");
                logInfo1.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                this.logService.insert(logInfo1);
                json.setReturnMsg("停止监视人员成功！");
                json.setReturnFlag(true);
            } else {
                json.setReturnMsg("停止监视人员失败！");
                json.setReturnFlag(false);
            }
        } catch (Exception var7) {
            LOG.error("停止监视人员失败！", var7, new String[0]);
            json.setReturnMsg("停止监视人员失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public void selectMonitorEmp() {
        try {
            Employee empl = this.employeeService.selectMonitorEmpl();
            String monitorMassage = null;
            if(empl != null) {
                if(Integer.valueOf(empl.getNamePy()).intValue() == 1) {
                    monitorMassage = empl.getName() + "上船了";
                } else {
                    monitorMassage = empl.getName() + "下船了";
                }
            }

            this.writeJson(monitorMassage);
        } catch (Exception var3) {
            ;
        }

    }

    public void punch() {
        PageJson json = new PageJson();
        int punchCount = this.employeeService.selectPunchCount();
        int noPunchCount = this.employeeService.selectNoPunchCount();
        this.getRequest().setAttribute("punchCount", Integer.valueOf(punchCount));
        this.getRequest().setAttribute("noPunchCount", Integer.valueOf(noPunchCount));

        try {
            String id = (String)("".equals(this.getRequest().getParameter("id"))?this.getRequest().getParameter("id"):this.getRequest().getAttribute("id"));
            String punch = "".equals(this.getRequest().getParameter("punch"))?this.getRequest().getParameter("punch"):this.getRequest().getAttribute("punch").toString();
            if(StringUtils.isBlank(id) || StringUtils.isBlank(punch)) {
                json.setReturnMsg("参数不完整，请重试！");
                json.setReturnFlag(false);
                this.writeJson(json);
                return;
            }

            Employee emp = (Employee)this.employeeService.selectByPrimaryKey(id, Employee.class);
            if(emp == null) {
                json.setReturnMsg("无法找到对应的数据！");
                json.setReturnFlag(false);
                this.writeJson(json);
                return;
            }

            if(emp.getPunch() != null && Integer.valueOf(punch).intValue() == emp.getPunch().intValue()) {
                json.setReturnMsg("请勿重复操作！");
                json.setReturnFlag(false);
                this.writeJson(json);
                return;
            }

            String time = DateUtil.getInstance().formatDate(new Date());
            LogInfo logInfo1;
            String namePy;
            Employee empl;
            if(Integer.valueOf(punch).intValue() == 1) {
                emp.setPunch(Short.valueOf(punch));
                emp.setPunchTime(time);
                this.employeeService.updateByPrimaryKey(emp);
                logInfo1 = new LogInfo();
                logInfo1.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                logInfo1.setId(UUID.randomUUID().toString());
                logInfo1.setTime(time);
                logInfo1.setMemo(emp.getName() + "上船");
                logInfo1.setFunc("上下船");
                logInfo1.setOp("上下船");
                logInfo1.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                this.logService.insert(logInfo1);
                namePy = emp.getNamePy();
                if(namePy != null) {
                    empl = new Employee();
                    empl.setId(UUID.randomUUID().toString());
                    empl.setName(emp.getName());
                    empl.setNamePy(emp.getNamePy());
                    empl.setCreateTime(DateUtil.getInstance().formatDate(new Date()));
                    this.employeeService.insertMonitorEmp(empl);
                }
            } else {
                emp.setPunch(Short.valueOf("0"));
                emp.setPunchTime("");
                this.employeeService.updateByPrimaryKey(emp);
                logInfo1 = new LogInfo();
                logInfo1.setUserName(RequestUtil.getSessionUserinfo().getUsername());
                logInfo1.setId(UUID.randomUUID().toString());
                logInfo1.setTime(time);
                logInfo1.setMemo(emp.getName() + "下船");
                logInfo1.setFunc("上下船");
                logInfo1.setOp("上下船");
                logInfo1.setUserId(RequestUtil.getSessionUserinfo().getUserid());
                this.logService.insert(logInfo1);
                namePy = emp.getNamePy();
                if(namePy != null) {
                    empl = new Employee();
                    empl.setId(UUID.randomUUID().toString());
                    empl.setName(emp.getName());
                    empl.setNamePy("2");
                    empl.setCreateTime(DateUtil.getInstance().formatDate(new Date()));
                    this.employeeService.insertMonitorEmp(empl);
                }
            }

            EmployeePunchHistory eph = new EmployeePunchHistory();
            eph.setId(UUID.randomUUID().toString());
            eph.setEmpId(id);
            eph.setPunchTime(time);
            eph.setPunch(Short.valueOf(punch));
            eph.setOperateId(RequestUtil.getSessionUserinfo().getUserid());
            eph.setCardNum("");
            eph.setPunchMachNo("");
            this.employeePunchHistoryService.insert(eph);
            json.setReturnMsg("上船成功！");
            json.setReturnFlag(true);
        } catch (Exception var12) {
            LOG.error("上船失败！", var12, new String[0]);
            json.setReturnMsg("上船人员失败！");
            json.setReturnFlag(false);
        }

        this.writeJson(json);
    }

    public void getNameSelectData() {
        try {
            List<SelectModel> list = this.employeeService.getNameSelectData();
            this.writeJson(list);
        } catch (Exception var2) {
            LOG.error("获取数据失败", var2, new String[0]);
        }

    }

    public Employee getModel() {
        return this.employee;
    }
}
